package me.zk.practice1.s;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author zhangkai
 * @date 2023/7/15 16:45
 */
public class LS_Offer_55_1 {
    public int maxDepth(TreeNode root) {
        return helper(root);
    }

    public int helper(TreeNode node) {
        if (node == null) {
            return 0;
        }
        return Math.max(helper(node.left),helper(node.right)) + 1;
    }

    public int maxDepth2(TreeNode root) {
        int res=0;
        if (root == null) {
            return res;
        }
        //队列
        Queue<TreeNode> queue = new LinkedList<>();

        queue.add(root);

        while (!queue.isEmpty()) {
            Queue<TreeNode> temp = new LinkedList<>();
            for (TreeNode node: queue) {
                if(node.left!= null) {
                    temp.offer(node.left);
                }
                if(node.right!= null) {
                    temp.offer(node.right);
                }
            }
            queue = temp;
            res++;

        }

        return res;
    }
}
